-
Notifications
You must be signed in to change notification settings - Fork 835
My Jetpack: Prevent red bubble fatals when notification data is malformed #45385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
We recently touched unread counts at #45350 so I hope that didn't cause anything. |
Thanks! I've checked and the error existed prior to that PR being merged. I suspect it's more likely some third-party code or strange config. Almost every instance of the error is on a single site. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes PHP fatal errors in the My Jetpack red bubble notifications feature by adding input validation to prevent array_map()
from being called on non-array data.
- Adds type checking before calling
array_map()
in the REST API sanitization callback - Returns an empty array when the parameter is not an array to prevent fatal errors
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
projects/packages/my-jetpack/src/class-red-bubble-notifications.php | Adds array type validation in sanitize_callback to prevent fatal errors |
projects/packages/my-jetpack/changelog/fix-my-jetpack-red_bubble_fatals | Documents the bug fix in the changelog |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks safe.
Closes MONOREP-131
There was a burst of these recently:
This PR ensures the data is an array before trying to run
array_map()
on it.Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
I suspect posting a string to
/wp-json/my-jetpack/v1/red-bubble-notifications
should trigger it, but I'm not familiar with the proper auth required to do a POST. As an aside, I'm not sure why this is usingWP_REST_Server::CREATABLE
instead ofWP_REST_Server::READABLE
...